package com.springhone.side.utils;

import java.io.BufferedInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

public class ConfigManager {

    private static final Logger logger = Logger.getLogger(ConfigManager.class);

    private static final String FILE_PATH = "/default.properties";

    private static ConfigManager instance = new ConfigManager();

    private Properties prop;

    public static ConfigManager getInstance() {
        if (instance == null) {
            instance = new ConfigManager();
        }
        return instance;
    }

    private ConfigManager() {
        prop = new Properties();
        try {
            InputStream is = new BufferedInputStream(this.getClass().getResourceAsStream(FILE_PATH));
            prop.load(is);
        } catch (FileNotFoundException e) {
            logger.error("load properties file " + FILE_PATH + " error", e);
        } catch (IOException e) {
            logger.error("load properties file " + FILE_PATH + " error", e);
        }
    }

    public String getProperty(String key) {
        return (String) prop.get(key);
    }

    public static void main(String[] args) {

        System.out.println(ConfigManager.getInstance().getProperty("app.type"));
    }

}
